<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
<!--            <div class="table-operator">-->
<!--                <a-button type="primary" icon="plus" @click="handleUpdate('add', {})" v-btnPermission="'bm_002_add_01'"-->
<!--                    >新增</a-button-->
<!--                >-->
<!--            </div>-->
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :isShowCountBar="false"
                :exportConfig="{ use: true,select: '标价分离',all: '标价分离'}"
                :exportPermission="{ select: 'bm_002_exp_03', all: 'bm_002_exp_03' }"
            >
                        <span
                                slot="serial"
                                slot-scope="text, record, index"
                        >{{ index + 1 }}</span>
                <div class="table-operateors mb12" slot="bottom">
                    <div class="pub-table-select-count">
                        <a-icon type="info-circle" theme="twoTone" />
                        <span>
                        中标价(不含税)(万元)：
                        <a>{{ from.bidPrice }}</a>
                    </span>
                        <a-divider type="vertical" />
                        <span>
                        标准成本(不含税)( 万元)：
                        <a>{{ from.standardCost }}</a>
                    </span>
                        <a-divider type="vertical" />
                        <span>
                        标价分离率(%)：
                        <a>{{ from.rate }}</a>
                    </span>
                        <a-divider type="vertical" />
                        <span>
                       间接费用占比(%)：
                        <a>{{ from.proportionOfExpensesRateAvg || 0}}</a>
                    </span>
                    </div>
                </div>
                <span slot="description" slot-scope="text">
                    <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
                </span>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleUpdate('look', record)" v-btnPermission="'bm_002_loo_02'">查看</a>
<!--                    <template v-if="record.auditStatus == 'SUBMITTED' && userId === record.creatorId&&hideBuquBtn()" >-->
<!--                        <a-divider type="vertical" />-->
<!--                        <a @click="handleUpdate('revoke', record)">撤销</a>-->
<!--                    </template>-->
<!--                    <template v-if="record.auditStatus === 'PAST'&&hideBuquBtn()" v-btnPermission="'bm_002_tov_05'">-->
<!--                        <a-divider type="vertical" />-->
<!--                        <a @click="handleUpdate('invalid', record)">作废</a>-->
<!--                    </template>-->
                    <template v-if="(record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST'&& record.auditStatus !='ABOLISH' )&&hideBuquBtn()" v-btnPermission="'bm_002_edi_01'">
                        <a @click="handleUpdate('edit', record)">编辑</a>
                    </template>
                         <a v-if="record.haveRecord " @click="handleUpdate('haveRecord', record)">补录</a>
<!--                    <template v-if="record.auditStatus == 'DRAFT'&&hideBuquBtn()" v-btnPermission="'bm_002_del_03'">-->
<!--                        <a-divider type="vertical" />-->
<!--                        <a @click="handleUpdate('del', record)">删除</a>-->
<!--                    </template>-->
                    <template
                        v-btnPermission="'bm_002_loo_02'"
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'
                        "
                    >
                        <a-divider type="vertical" />
                        <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
                    </template>
                        </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { getQuotationList, getQuotationListCount, delQuotationList, revokeQuotationList, invalidQuotationList,  } from '@/api/businessAffairs/priceSeparation'
import OrgTreeSelect from '@/components/OrgTreeSelect'
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' }
    },
    {
        title: '分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '项目名称',
        dataIndex: 'projectName',
    },
    {
        title: '中标价(不含税)( 万元)',
        dataIndex: 'bidPrice',
    },
    {
        title: '标准成本(不含税)( 万元)',
        dataIndex: 'standardCost',
    },
    {
        title: '标价分离率(%)',
        dataIndex: 'rate',
    },
    {
        title: '间接费用占比(%)',
        dataIndex: 'proportionOfExpensesRate',
    },
    {
        title: '标价分离时间',
        dataIndex: 'compleDate',
    },

    {
        title: '填报人',
        dataIndex: 'createName',
    },
    {
        title: '填报时间',
        dataIndex: 'createDate',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
        // scopedSlots: { customRender: 'auditStatus' },
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '230px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    {
        name: '标价分离时间',
        value: 'compleDate',
        type: 'dateRange',
    },
    {
        name: '填报人',
        value: 'informant',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval,
    },
]
import { typeListApproval } from '@/utils/util'
export default {
    name:'a'+Date.now(),
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            from: {},
            queryParam: {},
            userId:JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getQuotationListCount(requestParameters)
                const [err, res] = await getQuotationList(requestParameters)
                const statusMap = {
                            'DRAFT': '待提交审批',
                            'SUBMITTED': '审核中',
                            'PAST': '审核通过',
                            'REJECTED': '审核不通过',
                            'ABOLISH': '已发布'
                        }
                        res.data.forEach(item=>{
                            item.auditStatusName = statusMap[item.auditStatus]
                        })
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    methods: {
        //搜索
        search(val) {
            this.queryParam = {
                ...val,
                informantTimeBegin:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[0].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0,
                informantTimeEnd:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[1].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0,
                compleDateBegin: (val. compleDate &&
                        val. compleDate.length &&
                        val. compleDate[0].format('YYYY-MM-DD')) ||
                        void 0,
                compleDateEnd: (val. compleDate &&
                        val. compleDate.length &&
                        val. compleDate[1].format('YYYY-MM-DD')) ||
                        void 0,
            }
            delete this.queryParam.startEndDate
            delete this.queryParam.compleDate
            this.$refs.table.refresh(true)
        },
        async getQuotationListCount(requestParameters) {
            const [err, res] = await getQuotationListCount(requestParameters)
            if (!err) {
                this.from = res.data
            }
        },
        async delQuotationList(data) {
            const [err, res] = await delQuotationList({ id: data.id })
            if (!err) {
                this.$message.success('成功')
                this.$refs.table.refresh(true)
            }
        },
        //撤销
        async handleRevokeQuotationList(data) {
            const [err, res] = await revokeQuotationList({ id: data.id })
            if (!err) {
                this.$message.success('成功')
                this.$refs.table.refresh(true)
            }
        },
        //作废
        async handleInvalidQuotationList(data) {
            const [err, res] = await invalidQuotationList({ id: data.id })
            if (!err) {
                this.$message.success('成功')
                this.$refs.table.refresh(true)
            }
        },
        //新增
        async handleUpdate(type, data = {}) {
            if (type == 'del') {
                let that = this
                this.$confirm({
                    title: '温馨提示',
                    content: '确定是否删除数据？',
                    okText: '确认',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: () => {
                        return that.delQuotationList(data)
                    },
                })
            } else if(type == 'revoke'){
              let that = this
              this.$confirm({
                title: '温馨提示',
                content: '确定是否撤销数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk: () => {
                  return that.handleRevokeQuotationList(data)
                },
              })
            } else if(type == 'invalid'){
              let that = this
              this.$confirm({
                title: '温馨提示',
                content: '确定是否作废？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk: () => {
                  return that.handleInvalidQuotationList(data)
                },
              })
            } else {
                this.$router.push({
                    name: 'updatePriceSeparation',
                    query: {
                        id: data.id || '',
                        pageType: type,
                    },
                })
            }
        },
    },
}
</script>


